package tech.eyao.hs60x.property.editor;

import java.beans.PropertyEditorSupport;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * 自定义属性编辑器
 * @author hejian
 * @date 2018年3月16日 上午10:45:42
 */
public class CustomDateEditor extends PropertyEditorSupport {

	/**
	 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
	 */
	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		setValue(new Date(Long.decode(text)));
	}

	/**
	 * @see java.beans.PropertyEditorSupport#getAsText()
	 */
	@Override
	public String getAsText() {
		Date value = (Date) getValue();
		return (value != null ? String.valueOf(TimeUnit.MILLISECONDS.toSeconds(value.getTime())) : "");
	}

}
